<!doctype html>
<head>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8">
	<title>Horizontal scroll for Timeline view</title>

	<script src='../../codebase/dhtmlxscheduler.js?v=5.3.10' type="text/javascript" charset="utf-8"></script>
	<script src="../../codebase/ext/dhtmlxscheduler_limit.js?v=5.3.10" type="text/javascript" charset="utf-8"></script>
	<script src='../../codebase/ext/dhtmlxscheduler_timeline.js?v=5.3.10' type="text/javascript" charset="utf-8"></script>
	
	<link rel='stylesheet' type='text/css' href='../../codebase/dhtmlxscheduler_material.css?v=5.3.10'>
	
	<style type="text/css" >
		html, body{
			margin:0;
			padding:0;
			height:100%;
			overflow:hidden;
		}
	</style>

	<script type="text/javascript" charset="utf-8">
		function init() {

			scheduler.config.rtl = true;

			scheduler.locale.labels.timeline_tab = "Timeline";
			scheduler.locale.labels.section_custom="Section";
			scheduler.locale.labels.timeline_scale_header = "Sections";
			scheduler.config.details_on_create=true;
			scheduler.config.details_on_dblclick=true;

			//===============
			//Configuration
			//===============
			var sections=[];

			for(var i = 1; i < 200; i++){
				sections.push({key:i, label:"section " + i})
			}
			var days = 7;
			scheduler.createTimelineView({
				name:	"timeline",
				x_unit:	"hour",
				x_date:	"%H:%i",
				x_step:	1,
				x_size: 24*days,
				scrollable: true,
				scroll_position: new Date(2017, 6, 2),
				column_width:70,
				x_length:	24*days,
				y_unit:	sections,
				y_property:	"section_id",
				render:"bar",
                second_scale:{
                    x_unit: "day", // unit which should be used for second scale
                    x_date: "%F %d" // date format which should be used for second scale, "July 01"
                }
			});

			scheduler.ignore_timeline = function(date){
				if (date.getHours() > 12 && date.getHours() < 14)
					return true;
			};

			scheduler.addMarkedTimespan({  
				days:  "fullweek",
				zones: [14*60, 15*60] ,
				type:  "dhx_time_block"
			});

			//===============
			//Data loading
			//===============
			scheduler.config.lightbox.sections=[
				{name:"description", height:50, map_to:"text", type:"textarea" , focus:true},
				{name:"custom", height:30, type:"select", options:sections, map_to:"section_id" },
				{name:"time", height:72, type:"time", map_to:"auto"}
			];

			var start = new Date(2017,5,30)
			scheduler.init('scheduler_here',start,"timeline");
			scheduler.parse(generateEvents(start, scheduler.date.add(start, days, "day"), sections.length * 10, sections));


            function randomDate(date1, date2){
                function getRandomArbitrary(min, max) {
                    return Math.random() * (max - min) + min;
                }
                var date1 = date1 ;
                var date2 = date2;
                date1 = new Date(date1).getTime();
                date2 = new Date(date2).getTime();
                if( date1>date2){
                    return new Date(getRandomArbitrary(date2,date1))
                } else{
                    return new Date(getRandomArbitrary(date1, date2))

                }
            }

            function randomIntFromInterval(min,max)
            {
                return Math.floor(Math.random()*(max-min+1)+min);
            }

            function generateEvents(from, to, count, sections){
                var evs = [];
                for(var i = 0; i < count; i++){
                    var ev = {
                        section_id: sections[randomIntFromInterval(0, sections.length - 1)].key,
                        text: "event " + i,
						start_date: randomDate(from, to),
						id: scheduler.uid()
					}
					ev.end_date = scheduler.date.add(ev.start_date, randomIntFromInterval(1, 24), "hour");
                    evs.push(ev);
				}
				return evs;
			}
		}
	</script>
</head>
<body onload="init();">
	<div id="scheduler_here" class="dhx_cal_container" style='width:100%; height:100%;'>
		<div class="dhx_cal_navline">
			<div class="dhx_cal_prev_button">&nbsp;</div>
			<div class="dhx_cal_next_button">&nbsp;</div>
			<div class="dhx_cal_today_button"></div>
			<div class="dhx_cal_date"></div>
			<div class="dhx_cal_tab" name="day_tab" style="right:204px;"></div>
			<div class="dhx_cal_tab" name="week_tab" style="right:140px;"></div>
			<div class="dhx_cal_tab" name="timeline_tab" style="right:280px;"></div>
			<div class="dhx_cal_tab" name="month_tab" style="right:76px;"></div>
		</div>
		<div class="dhx_cal_header">
		</div>
		<div class="dhx_cal_data">
		</div>		
	</div>
</body>